package org.springframework.context.support;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;

/**
 * 实现了基本读取xml然后注册bean定义对象的功能
 */
public abstract class AbstractXmlApplicationContext extends AbstractRefreshableApplicationContext{
    /**
     * 基本实现加载资源的bean定义信息到bean工厂
     * @param beanFactory
     * @throws BeansException
     */
    @Override
    protected void loadBeanDefinitions(DefaultListableBeanFactory beanFactory) throws BeansException {
        //为什么这里的资源加载器传递的是this 因为ApplicationContext继承了资源加载器的接口
        //而且抽象的应用上下文类 还继承了默认的资源加载器
        XmlBeanDefinitionReader beanDefinitionReader = new XmlBeanDefinitionReader(beanFactory, this);

        String[] configLocations = getConfigLocations();
        if(configLocations != null){
            beanDefinitionReader.loadBeanDefinitions(configLocations);
        }
    }

    /**
     * 获得资源文件的路径
     * @return
     */
    protected abstract String[] getConfigLocations();
}
